package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyEkb;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyEkbParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyEkbService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.apache.commons.text.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.HtmlUtils;


/**
 * 控制器
 *
 * @author liuy
 * @Date 2021-08-09 10:42:46
 */
@Controller
@RequestMapping("/btyEkb")
public class BtyEkbController extends BaseController {

    private String PREFIX = "/modular/system/btyEkb";

    @Autowired
    private BtyEkbService btyEkbService;

    /**
     * 跳转到主页面
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyEkb.html";
    }


    @RequestMapping("/zx")
    public String zxList() {
        return PREFIX + "/btyZxEkb.html";
    }

    /**
     * 新增页面
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyEkb_add.html";
    }

    /**
     * 编辑页面
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyEkb_edit.html";
    }

    /**
     * 新增接口
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyEkbParam btyEkbParam) {
        this.btyEkbService.add(btyEkbParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyEkbParam btyEkbParam) {
        //替换大部分空白字符,不限于空格
        String yhk = btyEkbParam.getYhk().replaceAll("\\s*", "");
        String hh = btyEkbParam.getHh().replaceAll("\\s*", "");
        String fkr=btyEkbParam.getFkr();
        if(ToolUtil.isNotEmpty(fkr)){
            fkr= HtmlUtils.htmlUnescape(fkr.replace(" ",""));
        }
        btyEkbParam.setFkr(fkr);
        btyEkbParam.setYhk(yhk);
        btyEkbParam.setHh(hh);
        this.btyEkbService.update(btyEkbParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyEkbParam btyEkbParam) {
        this.btyEkbService.delete(btyEkbParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyEkbParam btyEkbParam) {
        BtyEkb detail = this.btyEkbService.getById(btyEkbParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyEkbParam btyEkbParam) {
        return this.btyEkbService.findPageBySpec(btyEkbParam);
    }

    /**
     * 查询列表
     *
     * @author liuy
     * @Date 2021-08-09
     */
    @ResponseBody
    @RequestMapping("/zxList")
    public LayuiPageInfo zxList(BtyEkbParam btyEkbParam) {
        return this.btyEkbService.findPageByZxList(btyEkbParam);
    }

}


